<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Document,
  Picture,
  VideoCamera,
  Edit,
  View,
  ArrowRight
} from '@element-plus/icons-vue'

// 组件名称
defineOptions({
  name: 'HomePage'
})

const router = useRouter()

// 主要功能模块
const features = ref([
  {
    title: '文档转换',
    description: '支持 PDF、Word 等文档格式转换',
    icon: Document,
    color: '#409eff',
    pathName: 'DocumentConvert',
    examples: ['PDF 转 Word', 'Word 转 PDF']
  },
  {
    title: '图片转换',
    description: '支持 JPG、PNG、ICO 等图片格式转换',
    icon: Picture,
    color: '#67c23a',
    pathName: 'ImageConvert',
    examples: ['JPG 转 PNG', 'PNG 转 ICO']
  },
  {
    title: '视频转换',
    description: '支持各种视频格式之间的转换',
    icon: VideoCamera,
    color: '#e6a23c',
    pathName: 'VideoConvert',
    examples: ['MP4 转 AVI', 'MOV 转 MP4']
  },
  {
    title: '音频转换',
    description: '支持各种音频格式之间的转换',
    color: '#f56c6c',
    pathName: 'AudioConvert',
    examples: ['MP3 转 WAV', 'WAV 转 MP3']
  }
])

// 工具功能
const tools = ref([
  {
    title: 'Markdown 编辑器',
    description: '所见即所得的 Markdown 编辑器',
    icon: Edit,
    color: '#909399',
    pathName: 'EditMarkdown'
  },
  {
    title: '文本预览',
    description: '预览各种文本文件内容',
    icon: View,
    color: '#606266',
    pathName: 'PreviewTextPlain'
  }
])

// 导航到具体功能
const navigateTo = (pathName: string) => {
  router.push({ name: pathName })
}
</script>

<template>
  <div class="home-page">
    <!-- 首屏介绍 -->
    <section class="hero-section">
      <div class="hero-content">
        <h1 class="hero-title">Free Convert</h1>
        <p class="hero-subtitle">免费在线文件转换工具</p>
        <p class="hero-description">
          支持文档、图片、视频、音频等多种格式转换，<br>
          纯前端实现，无需上传，保护您的隐私安全
        </p>
      </div>
    </section>

    <!-- 主要功能 -->
    <section class="features-section">
      <div class="section-header">
        <h2 class="section-title">主要功能</h2>
        <p class="section-subtitle">选择您需要的转换类型</p>
      </div>

      <div class="features-grid">
        <div v-for="feature in features" :key="feature.title" class="feature-card"
          @click="navigateTo(feature.pathName)">
          <div class="feature-icon" :style="{ color: feature.color }">
            <el-icon size="32">
              <component :is="feature.icon" />
            </el-icon>
          </div>
          <h3 class="feature-title">{{ feature.title }}</h3>
          <p class="feature-description">{{ feature.description }}</p>
          <div class="feature-examples">
            <span v-for="example in feature.examples" :key="example" class="example-tag">
              {{ example }}
            </span>
          </div>
          <div class="feature-action">
            <el-icon>
              <ArrowRight />
            </el-icon>
          </div>
        </div>
      </div>
    </section>

    <!-- 其他工具 -->
    <section class="tools-section">
      <div class="section-header">
        <h2 class="section-title">实用工具</h2>
        <p class="section-subtitle">更多实用的在线工具</p>
      </div>

      <div class="tools-grid">
        <div v-for="tool in tools" :key="tool.title" class="tool-card" @click="navigateTo(tool.pathName)">
          <div class="tool-icon" :style="{ color: tool.color }">
            <el-icon size="24">
              <component :is="tool.icon" />
            </el-icon>
          </div>
          <div class="tool-content">
            <h4 class="tool-title">{{ tool.title }}</h4>
            <p class="tool-description">{{ tool.description }}</p>
          </div>
          <div class="tool-action">
            <el-icon>
              <ArrowRight />
            </el-icon>
          </div>
        </div>
      </div>
    </section>

    <!-- 特性介绍 -->
    <section class="highlights-section">
      <div class="highlights-grid">
        <div class="highlight-item">
          <div class="highlight-icon">
            🔒
          </div>
          <h3 class="highlight-title">隐私安全</h3>
          <p class="highlight-description">
            纯前端实现，文件不会上传到服务器，保护您的隐私安全
          </p>
        </div>
        <div class="highlight-item">
          <div class="highlight-icon">
            ⚡
          </div>
          <h3 class="highlight-title">快速转换</h3>
          <p class="highlight-description">
            无需等待上传下载，本地实时处理，转换速度更快
          </p>
        </div>
        <div class="highlight-item">
          <div class="highlight-icon">
            🆓
          </div>
          <h3 class="highlight-title">完全免费</h3>
          <p class="highlight-description">
            所有功能完全免费，无需注册登录，随时随地使用
          </p>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
.home-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

/* 首屏区域 */
.hero-section {
  padding: 80px 20px;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.hero-content {
  max-width: 800px;
  margin: 0 auto;
}

.hero-title {
  font-size: 3.5rem;
  font-weight: 700;
  margin: 0 0 20px 0;
  background: linear-gradient(45deg, #fff, #f0f8ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.5rem;
  margin: 0 0 20px 0;
  opacity: 0.9;
  font-weight: 300;
}

.hero-description {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 0 0 40px 0;
  opacity: 0.8;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.hero-actions {
  margin-top: 40px;
}

.hero-actions .el-button {
  padding: 15px 40px;
  font-size: 16px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.hero-actions .el-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* 区域通用样式 */
.features-section,
.tools-section,
.highlights-section {
  padding: 80px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 60px;
}

.section-title {
  font-size: 2.5rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 15px 0;
}

.section-subtitle {
  font-size: 1.1rem;
  color: #7f8c8d;
  margin: 0;
}

/* 功能卡片 */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

.feature-card {
  background: white;
  border-radius: 16px;
  padding: 40px 30px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.feature-card:hover::before {
  transform: scaleX(1);
}

.feature-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  border-color: #e0e0e0;
}

.feature-icon {
  margin-bottom: 20px;
}

.feature-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 15px 0;
}

.feature-description {
  font-size: 1rem;
  color: #7f8c8d;
  line-height: 1.6;
  margin: 0 0 20px 0;
}

.feature-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}

.example-tag {
  background: #f8f9fa;
  color: #6c757d;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid #e9ecef;
}

.feature-action {
  color: #bdc3c7;
  font-size: 18px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.feature-card:hover .feature-action {
  opacity: 1;
}

/* 工具卡片 */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.tool-card {
  background: white;
  border-radius: 12px;
  padding: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  gap: 20px;
}

.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  border-color: #e0e0e0;
}

.tool-icon {
  flex-shrink: 0;
}

.tool-content {
  flex: 1;
}

.tool-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 8px 0;
}

.tool-description {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin: 0;
  line-height: 1.5;
}

.tool-action {
  color: #bdc3c7;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tool-card:hover .tool-action {
  opacity: 1;
}

/* 特性介绍 */
.highlights-section {
  background: #f8f9fa;
  border-radius: 20px;
}

.highlights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 40px;
}

.highlight-item {
  text-align: center;
}

.highlight-icon {
  font-size: 3rem;
  margin-bottom: 20px;
}

.highlight-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 15px 0;
}

.highlight-description {
  font-size: 1rem;
  color: #7f8c8d;
  line-height: 1.6;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .hero-section {
    padding: 60px 20px;
  }

  .hero-title {
    font-size: 2.5rem;
  }

  .hero-subtitle {
    font-size: 1.2rem;
  }

  .hero-description {
    font-size: 1rem;
  }

  .features-section,
  .tools-section,
  .highlights-section {
    padding: 60px 20px;
  }

  .section-title {
    font-size: 2rem;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .tools-grid {
    grid-template-columns: 1fr;
  }

  .tool-card {
    flex-direction: column;
    text-align: center;
    gap: 15px;
  }

  .highlights-grid {
    grid-template-columns: 1fr;
    gap: 30px;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 2rem;
  }

  .feature-card {
    padding: 30px 20px;
  }

  .tool-card {
    padding: 20px;
  }

  .hero-actions .el-button {
    padding: 12px 30px;
    font-size: 14px;
  }
}

/* 工具类 */
.ml-2 {
  margin-left: 8px;
}
</style>
